package lingnan.cn.edu.view;

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.List;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTextField;

import lingnan.cn.edu.User.Product;
import lingnan.cn.edu.service.ProductServiceImpl;
import lingnan.cn.edu.util.FontUtil;
import lingnan.cn.edu.util.MP3Player;
import lingnan.cn.edu.util.ShoppingCar;

public class Menu3View extends JPanel implements ActionListener{
	JLabel menu1,menu2,menu3,menu4,menu5,menu6,menu7,menu8,shop;
	JPanel mianPanel,shopPanel;
	JPanel countPanel;
	JSlider slider;
	public static JTextField countText;
	
	public Menu3View() {
		
		initView();
		//MainView cc = new MainView();
		//cc.getShoppingCar();
	}

	protected void initView() {
		ShoppingCar shoppingCar = MainView.getShoppingCar();
		
		this.setLayout(null);
		 mianPanel =new JPanel();
		 mianPanel.setLayout(new GridLayout(2, 3));
		 mianPanel.setBounds(50, -20, 800,800);
		 mianPanel.setBackground(null);
		 mianPanel.setOpaque(false);  
		 
		 shopPanel=new JPanel();
		 shopPanel. setBackground(null);
		 shopPanel.setBounds(640, 650, 500, 500);
		 
		//购物车右上角
		 countText = new JTextField(String.valueOf(MainView.count),3);
			countText.setBackground(new Color(0x58BAC8));
			 countText.setBorder(new RoundBorder(new Color(0x58BAC8)));
			 countText.setOpaque(false);
			 countText.setHorizontalAlignment(JTextField.CENTER);
			 countText.setEditable(false);	
			 countPanel = new JPanel();
			 countPanel.setBounds(800, 650, 50, 50);
			
			 countPanel.add(countText);
		// 
		 JButton bt=new JButton(new ImageIcon("static\\img\\shop.png"));
			bt.setBorder(null);//除去边框
	        bt.setContentAreaFilled(false);//除去默认的背景填充
			 shopPanel.add(bt);
			 bt.setFocusPainted(false);
			 bt.addActionListener(new ActionListener(){
				 @Override
				 public void actionPerformed(ActionEvent e) {
				 	new OrderView();
				 }
				 });
			 
		 


			 ProductServiceImpl productServiceImpl = new ProductServiceImpl();
			 List<Product> products = productServiceImpl.query();
			 
			
			 for(int i = 0;i<products.size();i++) {
				 if(products.get(i).getType().equals("牛奶冰沙")) {
					 Product product = products.get(i);
					
				    JLabel menu = new JLabel(new ImageIcon(products.get(i).getImg()));
				    menu.setText(products.get(i).getName());
					menu.setHorizontalTextPosition(JLabel.CENTER);
					menu.setVerticalTextPosition(JLabel.BOTTOM);
					menu.setFont(FontUtil.menuFont1);
					menu.addMouseListener(new MouseListener() {

						@Override
						public void mouseClicked(MouseEvent e) {
							shoppingCar.add(product);
							MainView.count+=1;
							countText.setText(String.valueOf(MainView.count));
							MP3Player mp3 = new MP3Player("static\\sound\\10569.mp3");
						    mp3.play();
							
						}

						@Override
						public void mousePressed(MouseEvent e) {
							 menu.setForeground(Color.white);
						}

						@Override
						public void mouseReleased(MouseEvent e) {
							// TODO Auto-generated method stub
							
						}

						@Override
						public void mouseEntered(MouseEvent e) {
							menu.setForeground(Color.white);
							
						}

						@Override
						public void mouseExited(MouseEvent e) {
							menu.setForeground(Color.black);
							
						}
						
					});
					mianPanel.add(menu);
					 
					}
				 
				 
			 }
			  
					 
			 

				
				this.add(mianPanel);
				this.add(countPanel);
				this.add(shopPanel);
				
	       
		

		}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
	}
	}





